﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using MVlog.Authorization;
using MVlog.Authorization.Users;
using MVlog.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVlog.Application
{
    [AbpAuthorize(AppPermissions.Pages_Message)]
    public class MessageAppService: AsyncCrudAppService<Message, MessageDto, long, GetMessageInput, CreateMessageInput, UpdateMessageInput>, IMessageAppService
    {
        private readonly UserManager _userManager;
        public MessageAppService(IRepository<Message, long> repository,UserManager userManager)
           : base(repository)
        {
            _userManager = userManager;
        }

        public override async Task<PagedResultDto<MessageDto>> GetAll(GetMessageInput input)
        {
            var Odata = (await Repository.GetAllListAsync()).Where(o => o.MessageToId == AbpSession.UserId).ToList();
            var list = ObjectMapper.Map<List<MessageDto>>(Odata);

            var count = Odata.Count();
            var data = list.AsQueryable().PageBy(input).ToList();
            return new PagedResultDto<MessageDto>(count, data);
        }
    }
}
